﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UnspscTests.cs" company="wwwlicious">
//   All rights reserved 2009.
// </copyright>
// <summary>
//   Summary description for UnitTest1
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Unspsc.Tests
{
    using System.Collections.Generic;
    using System.Linq;
    using NUnit.Framework;

    /// <summary>
	/// Summary description for UnitTest1
	/// </summary>
    [TestFixture]
	public class UnspscTests : TestBase
	{
		#region Segment Tests

        private double version = 1;

		[Test]
		public void UnspscRepositoryTestRepositorySegmentsIsNotNull()
		{
            Assert.IsNotNull(unspscRepository.GetSegments(version));
		}

		[Test]
		public void UnspscRepositoryTestRepositorySegmentsReturns5()
		{
            Assert.AreEqual(5, unspscRepository.GetSegments(version).Count());
		}

		[Test]
		public void UnspscServiceCanGetSegmentsFromService()
		{
            IList<IUnspscElement> list = unspscService.GetSegments(version);
			Assert.IsTrue(list.Count > 0);
		}

		#endregion

		#region Family Tests

		[Test]
		public void UnspscRepositoryTestRepositoryFamiliesIsNotNull()
		{
            IUnspscElement parent = unspscRepository.GetSegments(version).First();
            Assert.IsNotNull(parent);
            Assert.IsNotNull(unspscRepository.GetFamilies(parent.Code));
		}

		[Test]
		public void UnspscRepositoryTestRepositoryFamiliesReturns25()
		{
            IUnspscElement parent = unspscRepository.GetSegments(version).First();
            Assert.IsNotNull(parent);
            Assert.AreEqual(5, unspscRepository.GetFamilies(parent.Code, version).Count());
		}

		[Test]
		public void UnspscServiceCanGetFamiliesFromService()
		{
            IList<IUnspscElement> list = unspscService.GetFamilies(10000000d, version);
			Assert.IsTrue(list.Count > 0);
		}

		#endregion

		#region Class Tests

		[Test]
		public void UnspscRepositoryTestRepositoryClassesIsNotNull()
		{
            IUnspscElement parent = unspscRepository.GetSegments(version).First();
            Assert.IsNotNull(parent);
            IUnspscElement parent2 = unspscRepository.GetFamilies(parent.Code, version).First();
            Assert.IsNotNull(parent2);
            Assert.IsNotNull(unspscRepository.GetClasses(parent2.Code, version));
		}

		[Test]
		public void UnspscRepositoryTestRepositoryClassesReturns125()
		{
            IUnspscElement parent = unspscRepository.GetSegments(version).First();
            Assert.IsNotNull(parent);
            IUnspscElement parent2 = unspscRepository.GetFamilies(parent.Code, version).First();
            Assert.IsNotNull(parent2);
            Assert.AreEqual(5, unspscRepository.GetClasses(parent2.Code, version).Count());
		}

		[Test]
		public void UnspscServiceCanGetClassesFromService()
		{
            IList<IUnspscElement> list = unspscService.GetClasses(10200000d, version);
			Assert.IsTrue(list.Count > 0);
		}

		#endregion

		#region Commodity Tests

		[Test]
		public void UnspscRepositoryTestRepositoryCommoditiesIsNotNull()
		{
            IUnspscElement parent = unspscRepository.GetSegments(version).First();
            Assert.IsNotNull(parent);
            IUnspscElement parent2 = unspscRepository.GetFamilies(parent.Code, version).First();
            Assert.IsNotNull(parent2);
            IUnspscElement parent3 = unspscRepository.GetClasses(parent2.Code, version).First();
            Assert.IsNotNull(parent3);
            Assert.IsNotNull(unspscRepository.GetCommodities(parent3.Code, version));
		}

		[Test]
		public void UnspscRepositoryTestRepositoryCommoditiesReturns625()
		{
            IUnspscElement parent = unspscRepository.GetSegments(version).First();
            Assert.IsNotNull(parent);
            IUnspscElement parent2 = unspscRepository.GetFamilies(parent.Code, version).First();
            Assert.IsNotNull(parent2);
            IUnspscElement parent3 = unspscRepository.GetClasses(parent2.Code, version).First();
            Assert.IsNotNull(parent3);
            Assert.AreEqual(5, unspscRepository.GetCommodities(parent3.Code, version).Count());
		}

		[Test]
		public void UnspscServiceCanGetCommoditiesFromService()
		{
            IList<IUnspscElement> list = unspscService.GetCommodities(10201500d, version);
			Assert.IsTrue(list.Count > 0);
		}

		#endregion
	}
}
